/**  
 * @Title: DataXComp.java
 * @Description: TODO(描述)
 * @author liuyi
 * @date 2023-04-13 16:21:25 
 */  
package com.fsxgt.datagrid.component.handler.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fsxgt.datagrid.component.bo.CmpExecSqlBO;
import com.fsxgt.datagrid.component.service.impl.CmpExecSqlService;
import com.fsxgt.datagrid.ds.utils.ParamUtil;
import com.fsxgt.datagrid.flow.handler.FlowContext;
import com.fsxgt.datagrid.flow.handler.FlowReturn;
import com.fsxgt.datagrid.flow.handler.IComponentHandler;

import lombok.extern.slf4j.Slf4j;

/**  
 * @ClassName: DataxComponent
 * @Description: TODO(描述)
 * @author liuyi
 * @date 2023-04-13 16:21:25 
*/
@Slf4j
@Component
public class CmpExecSqlHandler extends IComponentHandler{
	
	@Autowired
	private CmpExecSqlService cmpExecSqlService;
	
	int i=4;


	public FlowReturn handler(final Object config,FlowContext context) throws Exception{
		
		CmpExecSqlBO bo=(CmpExecSqlBO)config;
		
		if(bo.getPreWaitTime()!=null&&bo.getPreWaitTime()>0) {
			Thread.sleep(bo.getPreWaitTime());
		}
		
		Map params=(Map) context.get(ParamUtil.PARAM_KEY);
		

		
		cmpExecSqlService.execSql(Long.valueOf(bo.getDatasourceId()),bo.getSqlText(),params,bo.getEnableMybatis(),bo.getEnableTransaction());
		
		return new FlowReturn();


	}
	
	
	

	
	

	/**  
	 * @Title: getName
	 * @Description: TODO(描述)
	 * @return 
	 * @see com.fsxgt.datagrid.core.handler.ICommonComponentHandler#getName() 
	 * @author liuyi
	 * @date 2023-04-14 13:49:53 
	 */ 
	@Override
	public String getComponentType() {
		// TODO Auto-generated method stub
		return "Exec Sql";
	}
	




	@Override
	public void stopHandler(Object config, FlowContext context) throws Exception {
		// TODO Auto-generated method stub

	}
	
	
	
}
